package com.cjj.controller;

import com.cjj.common.convention.result.Result;
import com.cjj.common.convention.result.Results;
import com.cjj.service.PostLikeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/postLike")
@RequiredArgsConstructor
public class PostLikeController {
    private final PostLikeService postLikeService;

    /**
     * 点赞帖子
     */
    @PostMapping("/{postId}/like")
    public Result<Void> likePost(@PathVariable Long postId, @RequestParam Long userId) {
        postLikeService.likePost(postId, userId);
        return Results.success();
    }

    /**
     * 取消点赞
     */
    @DeleteMapping("/{postId}/like")
    public Result<Void> unlikePost(@PathVariable Long postId, @RequestParam Long userId) {
        postLikeService.unlikePost(postId, userId);
        return Results.success();
    }

    /**
     * 获取用户点赞状态
     */
    @GetMapping("/{postId}/likeStatus")
    public Result<Boolean> getLikeStatus(@PathVariable Long postId, @RequestParam Long userId) {
        boolean hasLiked = postLikeService.hasLiked(postId, userId);
        return Results.success(hasLiked);
    }
}
